package com.lry.jvm.rtda.heap;

public class MethodLookup {


    public static JMethod lookupMethodInClass(JClass c, String name, String descriptor) {
        for(JClass jClass=c;jClass!=null;jClass=jClass.getSuperClass()){
            for(JMethod method:jClass.getMethods()){
                if(name.equals(method.getName())&&descriptor.equals(method.getDescriptor())){
                    return method;
                }
            }
        }
        return null;
    }

    public static JMethod lookupMethodInInterfaces(JClass[] interfaces, String name, String descriptor) {
        for(JClass jClass:interfaces){
            for(JMethod method:jClass.getMethods()){
                if(name.equals(method.getName())&&descriptor.equals(method.getDescriptor())){
                    return method;
                }
            }
            JMethod method = lookupMethodInInterfaces(jClass.getInterfaces(),name,descriptor);
            if(null!=method){
                return method;
            }
        }
        return null;
    }
}
